package com.ysd.lis.controller.emr;


import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.emr.EmrProcess;
import com.ysd.lis.entity.emr.EmrProcessDetailUser;
import com.ysd.lis.service.emr.EmrProcessDetailUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wh
 * @since 2025-06-10
 */
@RestController
@RequestMapping("/emr/processDetailUser")
public class EmrProcessDetailUserController extends BaseController {

    @Autowired
    private EmrProcessDetailUserService detailUserService;

    @ApiOperation("查询")
    @GetMapping("/findDetailUserList")
    public Result findDetailUserList(EmrProcessDetailUser processDetailUser) {
        return detailUserService.findDetailUserList(processDetailUser);
    }

    @ApiOperation("保存")
    @PostMapping("/addDetailUserList")
    public Result addDetailUserList(@RequestBody List<EmrProcessDetailUser> userList) {
        return detailUserService.addDetailUserList(userList);
    }

    @ApiOperation("删除")
    @PostMapping("/deleteDetailUserList")
    public Result deleteDetailUserList(@RequestBody List<EmrProcessDetailUser> userList) {
        List<String> ids = userList.stream().map(EmrProcessDetailUser::getId).collect(Collectors.toList());
        boolean b = detailUserService.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail("删除失败");
        }
    }
}
